package com.ling.module1sbbyyds.config.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
* mybatis-plus插入时自定义自动填充
* @author: ling
* @date: 2022/7/23
*/
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    private final String IS_DEL = "isDelete";
    private final String CREATE_DATE = "createDate";
    private final String UPDATE_DATE = "updateDate";

    @Override //1、重写插入时候的填充策略
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName(CREATE_DATE, new Date(), metaObject);
        this.setFieldValByName(UPDATE_DATE, new Date(), metaObject);
        this.setFieldValByName(IS_DEL, 0, metaObject);
    }

    @Override //2、重写修改时候的填充策略
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName(UPDATE_DATE, new Date(), metaObject);
    }
    
}